%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FB011;
%LET CLUSTER = 01;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS = 
    A1-A5 A99SP B1 C1 D1 E1 G99SP H1 H2 H3 H99SP 
    STOREBRAND BRAND_A--BRAND_P 
    I1 D16 D20 D24 D48 ENRICHED SLICED SANDWICH CINNAMON BUTTERMILK HONEY MNAMT MNAMTSQ
    ;

%LET STYR = 0201;
%LET FIRSTPER = 20&STYR.;
%LET LASTPER = 200709;
%LET STDUM = D&STYR.;
%LET RHYRS = D0202 -- D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + 41);

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;   
    IF FULLSAMP_EFFPR_WOTX < .9;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;    
    A1=(A="A1"); A2=(A="A2"); A3=(A="A3"); A4=(A="A4"); 
    A5=(A="A5"); A6=(A="A6");
    A99SP=(A="A99");


    ARRAY AARRAY (7) A1-A6 A99SP;
    DO COUNT=1 TO 7;
    IF A="" THEN AARRAY(COUNT)=.;
    END;

    B1=(B="B1");
    C1=(C="C1");
    D1=(D="D1");

    E1=(E="E1");
    E99SP=(E="E99");

    G99SP=(G="G99");

    H1=(H="H1");H2=(H="H2");H3=(H="H3");H4=(H="H4");
    H99SP=(H="H99");

    ARRAY HARRAY (5) H1-H4 H99SP;
    DO COUNT=1 TO 5;
    IF H="" THEN HARRAY(COUNT)=.;
    END;

    I1=(I="I1");I2=(I="I2");

    ARRAY iARRAY (2) I1-I2;
    DO COUNT=1 TO 2;
    IF I="" THEN IARRAY(COUNT)=.;
    END;

    K1=(K="K1");K2=(K="K2");K3=(K="K3");K4=(K="K4");
    K99SP=(K="K99");

    ARRAY KARRAY (5) K1-K4 K99SP;
    DO COUNT=1 TO 5;
    IF I="" THEN kARRAY(COUNT)=.;
    END;

    D99SP=(D="D99"); 
    E99SP=(E="E99"); 
    J99SP=(J="J99"); 
    K99SP=(K="K99");


    IF SUBSTR(K99,1,2)="1 " THEN OZ=16;
    IF SUBSTR(K99,1,2)="1 " AND FIND(K99,'4 OZ') THEN OZ=20;
    IF SUBSTR(K99,1,2)="1 " AND FIND(K99,'8 OZ') THEN OZ=24;
    IF SUBSTR(K99,1,2)="16" THEN OZ=16;
    IF SUBSTR(K99,1,2)="20" THEN OZ=20;
    IF SUBSTR(K99,1,2)="24" THEN OZ=24;
    IF SUBSTR(K99,1,2)="24" AND FIND(K99,'X') THEN OZ=48;
    IF SUBSTR(K99,1,2)="48" THEN OZ=48;

    D16=(OZ=16);
    D20=(OZ=20);
    D24=(OZ=24);
    D48=(OZ=48);

    IF J='J99' THEN BRAND=J99; ELSE IF J='J98' THEN BRAND=J98;
    IF J='J98' THEN STOREBRAND=1;ELSE STOREBRAND=0;
    IF FIND(J99,'**********','I')       THEN BRAND_A=1;ELSE BRAND_A=0;
    IF FIND(J99,'**********','I')       THEN BRAND_B=1;ELSE BRAND_B=0;
    IF FIND(J99,'**********','I')        THEN BRAND_C=1;ELSE BRAND_C=0;
    IF FIND(J99,'**********','I')  THEN BRAND_D=1;ELSE BRAND_D=0;
    IF FIND(J99,'**********','I')        THEN BRAND_E=1;ELSE BRAND_E=0;
    IF FIND(J99,'**********','I')       THEN BRAND_F=1;ELSE BRAND_F=0;
    IF FIND(J99,'**********','I')     THEN BRAND_G=1;ELSE BRAND_G=0;
    IF FIND(J99,'**********','I')      THEN BRAND_H=1;ELSE BRAND_H=0;
    IF FIND(J99,'**********','I')       THEN BRAND_J=1;ELSE BRAND_J=0;
    IF FIND(J99,'**********','I')      THEN BRAND_K=1;ELSE BRAND_K=0;    
    IF FIND(BRAND,'**********','I')    THEN BRAND_N=1;ELSE BRAND_N=0;
    IF FIND(BRAND,'**********','I')  THEN BRAND_P=1;ELSE BRAND_P=0;

    IF FIND(J99,'**********','I')      THEN STOREBRAND=1;
    IF FIND(J99,'**********','I')     THEN STOREBRAND=1;
    IF FIND(J99,'**********','I')       THEN STOREBRAND=1;
    IF FIND(J99,'**********','I')      THEN STOREBRAND=1;
    IF FIND(J99,'**********','I')     THEN STOREBRAND=1;
    IF FIND(J99,'**********','I')   THEN STOREBRAND=1;

    IF FIND(J98,'**********','I') THEN DO;
        STOREBRAND=0;
        BRAND_A=1;
    END;
    IF FIND(J98,'**********','I') THEN DO;
        STOREBRAND=0;
        BRAND_D=1;
    END;
    IF FIND(J98,'**********','I') THEN DO;
        STOREBRAND=0;
        BRAND_G=1;
    END;

    IF FIND(G99||J99,'ENRICHED','I') THEN ENRICHED=1;ELSE ENRICHED=0;
    IF FIND(G99||J99,'SLICED','I')  THEN SLICED=1;ELSE SLICED=0;
    IF FIND(G99||J99,'SANDWICH','I')  THEN SANDWICH=1;ELSE SANDWICH=0;
    IF FIND(G99||J99,'CINNAMON','I') THEN CINNAMON=1;ELSE CINNAMON=0;
    IF FIND(G99||J99,'BUTTERMILK','I') THEN BUTTERMILK=1;ELSE BUTTERMILK=0;
    IF FIND(G99||J99,'HONEY','I') THEN HONEY=1;ELSE HONEY=0;

    *;
    *ELIMINATE QUOTES WITH MISSING SPEC VARIABLES;
    *INCLUDE APPROPRIATE LIST OF SPEC VARIABLES HERE AND ELSEWHERE;
    *MODIFY SIZE OF SPECARRAY AS NEEDED TO NUMBER OF YOUR SPEC VARIABLES PLUS 5;
    *;

    ARRAY SPECARRAY (*) A1-A6 A99SP B1 C1 D1 
        E1 G99SP H1 H2 H3 H4 H99SP
        STOREBRAND BRAND_A--BRAND_P 
    I1 I2 D16 D20 D24 D48 ENRICHED SLICED SANDWICH CINNAMON BUTTERMILK HONEY DISCDEP--OTHSTORE;
    DO COUNT=1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)=. THEN DELETE;
    END;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";
